<!DOCTYPE html>
<html>
<head>
	<?php echo $this->Html->charset(); ?>
	<title>
		<?php echo $title_for_layout; ?>
	</title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<?php
		//echo $this->Html->css(array('/assets/bootstrap/css/bootstrap.min', '/assets/bootstrap/css/bootstrap-responsive.min'));
		echo $this->Html->css(array('application'));
		echo $this->Html->script(array('/assets/jquery/jquery.js','/assets/bootstrap/js/bootstrap.min', 'scripts'));
		echo $this->Html->meta('icon');

		echo $this->fetch('meta');
		echo $this->fetch('css');
		echo $this->fetch('script');
	?>
	<style type="text/css">
	body{
		padding-top: 60px;
		padding-bottom: 40px;
	}
	.sidebar-nav { padding: 9px 0; }
	</style>
</head>
<body>
	<!-- Top bar -->
	<div class="navbar navbar-fixed-top top-bar">
		<div class="navbar-inner">
			<div class="container">
				<?php echo $this->Html->link('Datamyze', '/channels', array('class' => 'brand', 'id' => 'topbar-brand')); ?>
				<div class="nav-collapse collapse">
					<?php if (isset($user) && !empty($user)): ?>
					<p class="navbar-text pull-right">
						Hello <?php echo $user['first_name']; ?> | <?php echo $this->Html->link('Logout', '/logout'); ?>
					</p>
					<?php else: ?>
					<form class="navbar-form pull-right" action="<?php echo $this->Html->url('/users/login'); ?>" method="post">
						<input class="span2" type="text" placeholder="Email" name="data[User][email]">
						<input class="span2" type="password" placeholder="Password" name="data[User][password]">
						<button type="submit" class="btn">Sign in</button>
					</form>					
					<?php endif; ?>
					<ul class="nav">
						<li><?php echo $this->Html->link('Home', '/channels'); ?></li>
						<?php if (!empty($user)): ?>
						<li class="dropdown">
							<?php echo $this->Html->link('Sites', '#', array('data-toggle' => 'dropdown','class' => 'dropdown-toggle')); ?> 
							<ul class="dropdown-menu">
								<li><?php echo $this->Html->link('Add new site', '/channels/add'); ?></li>
								<li class="divider"></li>
								<?php 
								$user_channels = $this->requestAction('/channels/user/'.$user['id']);
								if (!empty($user_channels)):
								?>
								<?php foreach ($user_channels as $channel): ?>
								<li><?php echo $this->Html->link($channel['Channel']['name'], array('controller' => 'channels', 'action' => 'view', $channel['Channel']['id'] )); ?></li>
							<?php endforeach; ?>
							<?php endif; ?>
	                        </ul>
	                    </li>
	                <?php else: ?>
	                	<li><?php echo $this->Html->link('Sign-up', '/signup'); ?></li>
						<?php endif; ?>
					</ul>
					<?php if (empty($user)): ?>

					<?php endif; ?>
				</div>
			</div>
		</div>
	</div>

	<!-- Content -->
	<div class="container-fluid">
		<?php echo $this->Session->flash(); ?>
		<?php echo $this->fetch('content'); ?>
	</div>

	<!-- Footer -->
	<div id="footer">
		
	</div>
	<?php //echo $this->element('sql_dump'); ?>
</body>
</html>
